package model

// by daoyi
import (
	"gorm.io/gorm"
	"simai_oa/tool"
)

// 人员关系表
type Contact struct {
	gorm.Model
	OwnerId  uint //谁的关系
	TargetId uint //对应的人
	Type     int  //对应的类型
	Desc     string
}

func SearchFriend(userId any) []UserBasic {
	contacts := make([]Contact, 0)
	objIds := make([]uint64, 0)
	tool.Gdb.Where("owner_id = ? and type=1", userId).Find(&contacts)
	for _, v := range contacts {
		objIds = append(objIds, uint64(v.TargetId))
	}
	users := make([]UserBasic, 0)
	tool.Gdb.Where("id in ?", objIds).Find(&users)
	return users
}
